<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src='./Promise_class.js'></script>
</head>
<body>
    <script>
        let p = new Promise((resolves,rejected)=>{
            //resolves('ok')
            //throw 'error'
            //throw想到try-catch
            //上面修改了状态所以下面无法调用
           
                rejected('success')
                console.log('11111')
        
            //resolves('okkk')
            // rejected('rejected--')
        })
        // const res1 = p.catch(reason =>{
        //     console.log(reason)
        // })
        // console.log(res1)
        // const res2 = p.then(r =>{
        //     console.log(r)
        // },v => {
        //     console.log(v)
        // })
        // console.log(res2)
       
    //    const res2 = p.then(value=>{
    //         // return new Promise((resolved,rejected)=>{
    //         //     resolved('success')
    //         // })
    //         //z注意返回，如果是输出console那么返回结果是undefined
    //         return 'success'
    //    },error=>{
    //         throw 'errrrrrr'
    //    })
    //     console.log('res ----',res2)
    //如果想多次调用then方法
       p.then(value=>{
            console.log('333333')
        },reason=>{
            console.log('444444')
        })
        //console.log(p)
    //异常穿透
    // p.then()
    // .then(v =>{
    //     console.log('1')
    // }).then(v =>{
    //     console.log('2')
    // }).then( v=>{
    //     console.log('3')
    // }).then(v =>{
    //     console.log('4')
    // }).catch(e => {
    //     console.log(e)
    // })
    //注意这里没有穿失败函数的回调，则是undefined，也就是onrejected没有定义
    //所以会抛出错误
    // const res3 = Promise.resolve('res3')
    // const res4 = Promise.reject('res4')
    // const res8 = Promise.reject('res8')
    //根据回调，返回的promise对象是什么结果最后就是什么结果
    //console.log(res4)
    // const res5 = Promise.reject('error')
    // const res6 = Promise.reject(new Promise((resolve,reject) =>{
    //     resolve('okkk')
    // })
    // )
    // const res7 = Promise.reject(new Promise((resolve,reject) =>{
    //     reject('errrrrrrrdjnv')
    // })
    // )
    // console.log(res6)
    // console.log(res7)
    //const res9 = Promise.all([res3,res4,res8])
    // const res10 = Promise.race([res4,res3,res8])
    // console.log(res10)

    console.log('2222222')
    </script>
</body>
</html>